package com.zhangwei.expands;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.zhangwei.expands.adapter.MainPagerAdapter;
import com.zhangwei.expands.recycler.HotFragment;
import com.zhangwei.expands.recycler.RecyclerViewFragment;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.fab)
    FloatingActionButton fab;
    @Bind(R.id.tabs)
    TabLayout tabs;
    @Bind(R.id.fragments)
    ViewPager fragments;
    @Bind(R.id.vertical_txt)
    TextView verticalTxt;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();

        verticalTxt.setMovementMethod(ScrollingMovementMethod.getInstance());
        showMaterialDialog();
    }


    private void showMaterialDialog() {
//        final MaterialDialog dialog = new MaterialDialog(this);
//        dialog.setTitle("MaterialDialog");
//        dialog.setBackgroundResource(R.color.dark_background);
//        dialog.setMessage("呵呵");
//        dialog.setNegativeButton("取消", new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dialog.dismiss();
//            }
//        });
//        dialog.setPositiveButton("确定", new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dialog.dismiss();
//            }
//        });
//        dialog.show();
    }

    private void initView() {
        setSupportActionBar(toolbar);
        fab.setOnClickListener(this);
        tabs.addTab(tabs.newTab().setText("RecyclerView"));
        tabs.addTab(tabs.newTab().setText("即时通信"));
        tabs.addTab(tabs.newTab().setText("验证框架"));
        ArrayList<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(HotFragment.newInstance());
        fragmentList.add(RecyclerViewFragment.newInstance());
        fragmentList.add(RecyclerViewFragment.newInstance());
        fragments.setAdapter(new MainPagerAdapter(getSupportFragmentManager(), fragmentList));
        tabs.setupWithViewPager(fragments);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {

    }
}
